package com.yjhb.android.sbz.activity;

import android.content.Intent;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.fragment.mytask.DoingFragment;
import com.yjhb.android.sbz.fragment.mytask.PassFragment;
import com.yjhb.android.sbz.fragment.mytask.UnCheckFragment;
import com.yjhb.android.sbz.fragment.mytask.UnPassFragment;
import com.yjhb.android.sbz.tool.MsgReadTool;
import com.yjhb.android.sbz.tool.Tool;
import com.jojo.android.zxlib.adapter.FragmentAdapter;
import com.jojo.android.zxlib.base.BaseFragment;
import com.jojo.android.zxlib.base.mvp.BasePresenter;
import com.jojo.android.zxlib.tool.ZxTool;
import com.qmuiteam.qmui.widget.QMUITabSegment;
import com.tencent.qcloud.tim.uikit.UnReadManager;
import com.tencent.qcloud.tim.uikit.config.SysUserConfig;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2020/12/17 10:49
 */
public class MyTaskActivity extends BaseActivity {
    private final String TAG = "MyTaskActivity";


    @BindView(R.id.tabLayout)
    QMUITabSegment tabLayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;

    private MsgReadTool readTool;
    List<BaseFragment> fragments = new ArrayList<>();
    DoingFragment doingFragment;
    UnCheckFragment unCheckFragment;
    PassFragment passFragment;
    UnPassFragment unPassFragment;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_task;
    }

    @Override
    protected void initUI() {
        initFragments();
        readTool = new MsgReadTool();
        readTool.loadSystemNotice(SysUserConfig.TASK_NOTICE.getId());
        UnReadManager.getInstance().setUnreadTask(0);
    }

    @Override
    protected void initData() {

    }
    @Override
    protected void onDestroy() {
        if (readTool != null) {
            readTool.destroyChat();
        }
        super.onDestroy();
    }

    @Override
    protected void regEvent() {

    }

    private void initFragments() {
        fragments.clear();
        fragments.add(doingFragment = new DoingFragment());
        fragments.add(unCheckFragment = new UnCheckFragment());
        fragments.add(passFragment = new PassFragment());
        fragments.add(unPassFragment = new UnPassFragment());
        viewpager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), fragments));

        tabLayout.setDefaultNormalColor(getResources().getColor(R.color.gray_66));
        tabLayout.setDefaultSelectedColor(getResources().getColor(R.color.colorPrimaryDark));
        tabLayout.setTabTextSize(ZxTool.dip2px(14));
        tabLayout.setupWithViewPager(viewpager);
    }

    @OnClick(R.id.back)
    void back() {
        finish();
    }

    @OnClick(R.id.title_right_tv)
    void title_right_tv() {
        Tool.showPopupRules(this,findViewById(R.id.title_right_tv));
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Tool.PictureSelectedSuccessSendMsg(requestCode, resultCode, data);
    }
}
